#!/bin/bash

set -e

case $1 in
    remove|upgrade)
                INITSYS=$(ls -al /proc/1/exe | awk -F' ' '{print $NF}' | awk -F'/' '{print $NF}')
                if [ "systemd" == "${INITSYS}" ]; then
                        systemctl stop hoptodesk || true
                        systemctl disable hoptodesk || true
                        rm /etc/systemd/system/hoptodesk.service || true
                elif [ "init" == "${INITSYS}" ]; then
                        service hoptodesk stop || true
                        systemctl disable hoptodesk || true
						command -v systemctl >/dev/null 2>&1 && systemctl disable hoptodesk || true
						pkill -3 hoptodesk || true
                        insserv -rv hoptodesk || true
                fi
        ;;
esac

exit 0
